home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / filesyst / ncpfs / mars_dos.000 / mars_dos / netpc / net.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-21  |  3.6 KB  |  124 lines

  1. /* net.c */
  2. #define VERS_DATE "21-May-96"
  3. /* simple client program to act with mars_nwe */
  4.  
  5. /****************************************************************
  6.  * (C)opyright (C) 1993,1996  Martin Stover, Marburg, Germany   *
  7.  ****************************************************************/
  8.  
  9. #include "net.h"
  10.  
  11. char *funcname=NULL;
  12. char  prgpath[65];
  13.  
  14. typedef int (*NET_FUNC)(int argc, char *argv[], int mode);
  15.  
  16. static struct s_net_functions {
  17.  char      *name;
  18.  char      *description;
  19.  NET_FUNC  func;
  20.  int       mode;
  21. } net_functions[] = {
  22.  
  23. {"SPAWN",  "spawn program(command file)" ,          func_exec   , 0},
  24. {"EXEC",   "execute program(command file)",         func_exec   , 1},
  25. {"ECHO",   "echoes string (command file)" ,         func_echo   , 0},
  26. {"CD",     "change directory (command file)" ,      func_cwd    , 0},
  27. {"LOGIN",  "login to server as user" ,              func_login  , 0},
  28. {"PROFILE","read command file" ,                    func_profile, 0},
  29. {"CAPTURE","list and redirect printers" ,           func_capture, 0},
  30. {"ENDCAP", "cancel redirect printers" ,             func_capture, 1},
  31. {"MAP",    "list maps and map drives" ,             func_map    , 0},
  32. {"MAPDEL", "removes maps" ,                         func_map    , 1},
  33. {"PATH",   "list and set search path" ,             func_path   , 0},
  34. {"PATHDEL","removes search path" ,                  func_path   , 1},
  35. {"PATHINS","insert search path" ,                   func_path   , 2},
  36. {"LOGOUT", "logout from server",                   func_logout , 0},
  37. #if 0
  38. {"SLIST",  "list servers",                      func_slist  , 0},
  39. #endif
  40. {"PASSWD", "change password",                      func_passwd , 0},
  41. #if 1
  42. {"TESTS",  "only testroutines!",                    func_tests  , 0},
  43. #endif
  44. {"DEBUG",  "set debug level, for mars_nwe only !",  func_debug  , 0}
  45. };
  46.  
  47. #define MAX_FUNCS  (sizeof(net_functions) / sizeof(struct s_net_functions))
  48.  
  49. static int get_entry_nr(char *fstr)
  50. {
  51.   int       entry    = MAX_FUNCS;
  52.   char      buff[200];
  53.   char      funcn[100];
  54.   char      *pp;
  55.   strmaxcpy(buff, fstr, sizeof(buff)-1);
  56.   korrpath(buff);
  57.   get_path_fn(buff, NULL, funcn);
  58.   pp=strrchr(funcn, '.');
  59.   if (NULL != pp) *pp = '\0';
  60.   upstr(funcn);
  61.   while (entry--) {
  62.     if (!strcmp(funcn, net_functions[entry].name)) return(entry);
  63.   }
  64.   return(-1);
  65. }
  66.  
  67. int call_func_entry(int argc, char *argv[])
  68. {
  69.   int       funcmode;
  70.   int       result   = -1;
  71.   NET_FUNC  func     = NULL;
  72.   int       entry = get_entry_nr(argv[0]);
  73.   if (entry > -1) {
  74.     func     = net_functions[entry].func;
  75.     funcmode = net_functions[entry].mode;
  76.     funcname = net_functions[entry].name;
  77.   }
  78.   if (NULL != func) {
  79.     if (ipx_init() || func == func_map) {
  80.       result = (*func)(argc, argv, funcmode);
  81.     } else {
  82.       fprintf(stderr, "Cannot init IPX\n");
  83.     }
  84.   } else result = -0xff;
  85.   return(result);
  86. }
  87.  
  88. static void get_path(char *path)
  89. {
  90.   char buf[100];
  91.   strmaxcpy(buf, path, sizeof(buf)-1);
  92.   korrpath(buf);
  93.   get_path_fn(buf, prgpath, NULL);
  94. }
  95.  
  96. int main(int argc, char *argv[])
  97. {
  98.   int result = -0xff;
  99.   get_path(argv[0]);
  100.   result = call_func_entry(argc, argv);
  101.   if (result == -0xff)
  102.     result = call_func_entry(argc-1, argv+1);
  103.   if (result == -0xff) {
  104.     int  k= MAX_FUNCS;
  105.     char progname[256];
  106.     strmaxcpy(progname, argv[0], sizeof(progname)-1);
  107.     upstr(progname);
  108.     fprintf(stderr, "\n"
  109.      "* (C)opyright (C) 1993,1996  Martin Stover, Marburg, Germany *\n"
  110.      "  Version: %s\n\n", VERS_DATE);
  111.  
  112.     fprintf(stderr, "Usage:\t%s func ... \nfuncs:", progname);
  113.     while (k--) {
  114.       if (net_functions[k].func) {
  115.         fprintf(stderr, "\t%s\t: %s\n",
  116.            net_functions[k].name, net_functions[k].description);
  117.       }
  118.     }
  119.   }
  120.   return(result);
  121. }
  122.  
  123.  
  124.